<template>
  <div class="operation">
    <van-cell class="content">
      <div class="flex-between line-height-3">
        <div class="col-333333 font-bold-500 font-15 m-r-10">{{ objContent.title }}</div>
      </div>
      <div class="flex-between font-12 line-height-3">
        <div class="col-666666 m-r-10 line-text-out"></div>
      </div>

      <div class="flex-between font-12 line-height-3">
        <div class="col-666666 m-r-10 line-text-out">
          {{ objContent.createTime }}
        </div>
        <div class="col-666666 m-r-10 line-text-out" v-if="collectionState" @click="goCollection">已收藏</div>
        <div class="col-666666 m-r-10 line-text-out" v-else @click="goCollection">收藏</div>
      </div>
      <div class="flex-between line-height-3" style="margin-top: 5px">
        <div class="col-333333 font-bold-400 font-14 m-r-10">浏览量：{{ objContent.pageViewNums }}</div>
      </div>
      <div class="col-333333 content_x font-bold-400 font-14" v-html="objContent.content"></div>
    </van-cell>
  </div>
</template>
<script>
import { Swipe, SwipeItem, Cell, Toast } from 'vant'
import { getValue } from '../../utils/auth'
import { getHandle, postHandle } from '@/api'

export default {
  name: '',
  components: {
    [Swipe.name]: Swipe,
    [SwipeItem.name]: SwipeItem,
    [Cell.name]: Cell
  },
  data() {
    return {
      id: getValue('policyForDetails-view-id'),
      collectionState: false,
      current: 0,
      bannerList: [],
      objContent: {},
      params: {
        recordId: getValue('policyForDetails-view-id'),
        type: 3,
        loginUserId: getValue('loginUserId')
      }
    }
  },
  created() {
    this.initialize()
  },
  mounted() {},
  methods: {
    initialize() {
      getHandle(`/agri/api/sshfw/news/detail/${this.id}`).then(res => {
        this.objContent = res.data
      })

      getHandle(`/agri/api/shhfw/collection/isStore`, this.params).then(res => {
        this.collectionState = res.data
      })
    },
    goCollection() {
      if (this.collectionState) {
        // 已收藏取消收藏
        postHandle(`/agri/api/shhfw/collection/delete/${this.id}/${this.params.loginUserId}`).then(res => {
          this.collectionState = res.data
          if (res.status === 0) {
            this.collectionState = false
            Toast('取消收藏')
          }
        })
      } else {
        postHandle(`/agri/api/shhfw/collection/save`, {
          recordId: this.id,
          type: 3
        }).then(res => {
          if (res.status === 0) {
            this.collectionState = true
            Toast('收藏成功')
          }
        })
      }
    },

    onChange(index) {
      this.current = index
    }
  }
}
</script>
<style lang="scss" scoped>
::v-deep .content_x img{
    width: 100%;
}
.allowgetattach {
  > button {
    width: 68px;
    height: 24px;
    border-radius: 2px;
    border: 1px solid #37b5b5;
    background-color: #fff;
    font-size: 13px;
    font-weight: 400;
    color: #37b5b5;
    line-height: 24px;
    margin-left: 10px;
  }
}
.pStyle {
  font-size: 12px;
  font-weight: 400;
  color: #ff0000;
  margin-left: 15px;
}
.m-t-10 {
  margin-top: 10px !important;
}
.content {
  padding: 10px;
}
.custom-indicator {
  position: absolute;
  right: 5px;
  bottom: 5px;
  padding: 2px 5px;
  font-size: 12px;
  background: rgba(0, 0, 0, 0.1);
}
</style>
